<template>
	<div>
		<!-- 运单卸车提示窗 -->
		<uni-popup ref="unloadDialog" type="dialog">
			<uni-popup-dialog type="info" cancelText="关闭" confirmText="确认卸车" title="运单卸车"
				@confirm="unloadDialogConfirm">
				<scroll-view scroll-top="0" scroll-y="true" style="height: 300px;">
					<uni-forms ref="form_truckLoading" :modelValue="formData_truckLoading" :rules="rules_truckLoading" labelWidth="75px">
						<uni-forms-item label="卸货人" name="loadUserName" required>
							<uni-easyinput  type="text" v-model="formData_truckLoading.loadUserName" placeholder="请输入卸货人" />
							<!-- <uni-easyinput @focus="CopyInfoFlag1=true" @blur="CopyInfoFlag1=false" style="position: relative;" type="text" v-model="formData_truckLoading.loadUserName" placeholder="请输入卸货人" />
							<view v-if="CopyInfoFlag1"  @click="selectCopyInfo" style="height: 35px;width: 118px;background-color: #333333;color:white;z-index: 999;border-radius: 4px;position: absolute;top: 40px;left: 0;font-size: 12px;display: flex;justify-content: center;align-items: center;">
								{{formData.scheduleVo.driverVo.driverName}} {{formData.scheduleVo.driverVo.phoneNumber}}
							</view> -->
						</uni-forms-item>
						<uni-forms-item label="联系电话" name="contactPhone" required>
							<uni-easyinput  type="number" v-model="formData_truckLoading.contactPhone" placeholder="请输入联系电话" />
							<!-- <uni-easyinput @focus="CopyInfoFlag2=true" @blur="CopyInfoFlag2=false" style="position: relative;" type="number" v-model="formData_truckLoading.contactPhone" placeholder="请输入联系电话" />
							<view v-if="CopyInfoFlag2" @click="selectCopyInfo" style="height: 35px;width: 118px;background-color: #333333;color:white;z-index: 999;border-radius: 4px;position: absolute;top: 40px;left: 0;font-size: 12px;display: flex;justify-content: center;align-items: center;">
								{{formData.scheduleVo.driverVo.driverName}} {{formData.scheduleVo.driverVo.phoneNumber}}
							</view> -->
						</uni-forms-item>
						<uni-forms-item label="卸货费" name="cost">
							<uni-easyinput type="text" v-model="formData_truckLoading.cost" placeholder="请输入卸货费" />
						</uni-forms-item>
						<uni-forms-item label="分摊方式" name="allocationMethod">
							<uni-data-select v-model="formData_truckLoading.allocationMethod" :localdata="allocationMethod"
								style="background-color: white;" />
						</uni-forms-item>
						<uni-forms-item label="备注">
							<uni-easyinput type="textarea" v-model="formData_truckLoading.remark" placeholder="卸货相关备注说明" />
						</uni-forms-item>
					</uni-forms>
					<view style="height: 50px;"></view>
				</scroll-view>
			</uni-popup-dialog>
		</uni-popup>
		<!-- 取消卸车提示窗 -->
		<uni-popup ref="cancelUnloadDialog" type="dialog">
			<uni-popup-dialog type="info" cancelText="关闭" confirmText="确认" title="取消运单卸车"
				@confirm="cancelUnloadDialogConfirm">
				<scroll-view scroll-top="0" scroll-y="true" style="height: 100px;">
					<view style="display: flex;flex-direction: column;width: 100%;">
						<view style="display: flex;margin-top: 10px;color: #bf5f09;">
							<text>*确认取消当前运单{{formData.scheduleNo}}卸车</text>
						</view>
					</view>
				</scroll-view>
			</uni-popup-dialog>
		</uni-popup>
	</div>
</template>

<script>
	import {
		waybillTruckLoading,
		cancelWaybillTruckLoading,
	} from '@/api/system/waybill.js'
	import {getDicts} from '@/api/system/dict.js'
	export default {
		props: {
			data: {
				type: Object,
				default: {}
			},
			waybillId:{
				type: String,
				default:''
			}
		},
		data() {
			return {
				formData:{},
				//装车
				formData_truckLoading:{
					loadUserName:'',
					contactPhone:'',
					cost:'',
					allocationMethod:'',
					remark:''
				},
				// 校验规则->装车
				rules_truckLoading: {
					loadUserName: {
						rules: [{
							required: true,
							errorMessage: '请输入装货人',
						}]
					},
					contactPhone: {
						rules: [{
							required: true,
							errorMessage: '请输入联系电话',
						},
						{
						    pattern: '^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$',
						    errorMessage: '电话格式不正确'
						}
						]
					}
				},
				//下拉框->分摊方式
				allocationMethod:[],
				
				CopyInfoFlag1:false,
				CopyInfoFlag2:false
			}
		},
		watch: {
			data: {
			　　handler(newValue, oldValue) {
			　　　	this.formData=newValue
			　　},
			　　deep: true
			},
		},
		created() {
			//下拉框->分摊方式
			getDicts('allocation_method').then(res=>{
				this.allocationMethod=res.data.map(item=>{
					return {
						value:item.dictValue,
						text:item.dictLabel
					}
				})
			})
		},
		methods: {
			selectCopyInfo(){
				this.formData_truckLoading.loadUserName=this.formData.scheduleVo.driverVo.driverName
				this.formData_truckLoading.contactPhone=this.formData.scheduleVo.driverVo.phoneNumber
				this.CopyInfoFlag1=false
				this.CopyInfoFlag2=false
			},
			//卸车
			unload(){
				//装车默认装车人、电话为司机和司机电话
				this.formData_truckLoading.loadUserName=this.formData.scheduleVo.driverVo.driverName
				this.formData_truckLoading.contactPhone=this.formData.scheduleVo.driverVo.phoneNumber
				this.$refs.unloadDialog.open()
			},
			//确认卸车
			unloadDialogConfirm(){
				uni.showLoading({
					title: '正在卸车...',
				})
				//卸车完成
				this.formData_truckLoading.waybillIds=[parseInt(this.waybillId)]; //装车运单ID集合
				this.formData_truckLoading.type=1;  //类型(0装车1卸车)
				waybillTruckLoading(this.formData_truckLoading).then(res => {
					uni.hideLoading()
					if (res.code == '200') {
						uni.showToast({
							title: '卸车成功',
							icon: 'none'
						})
						
						this.$parent.init()  //调用父组件的init函数，重新加载数据
						//this.$forceUpdate(); //重新加载数据
					} else {
						uni.showToast({
							icon: 'none',
							title: res.msg
						})
					}
				})
			},
			//取消卸车
			cancelUnload(){
				this.$refs.cancelUnloadDialog.open()
			},
			//确认取消卸车
			cancelUnloadDialogConfirm(){
				uni.showLoading({
					title: '正在取消卸车...',
				})
				cancelWaybillTruckLoading(1,this.formData.loadId).then(res => {
					uni.hideLoading()
					if (res.code == '200') {
						uni.showToast({
							title: '取消卸车成功',
							icon: 'none'
						})
						
						this.$parent.init()  //调用父组件的init函数，重新加载数据
						//this.$forceUpdate(); //重新加载数据
					} else {
						uni.showToast({
							icon: 'none',
							title: res.msg
						})
					}	
				})
			},
		},
	}
</script>

<style scoped>

</style>